﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class Admin_upYg : System.Web.UI.Page
{
    AccessDAO dao = new AccessDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
        IsAdmin.Admin();
        this.btnSubmit.Attributes.Add("onclick", "javascript:succShow();");

        if (!Page.IsPostBack)
        {
            int id = Convert.ToInt32(Session["manId"].ToString());
            string sql = "select * from workMan where id=" + id;
            DataSet ds = dao.getDs(sql);
            foreach (DataRow dr in ds.Tables["message"].Rows)
            {
                this.txtName.Text = dr["name"].ToString();
                this.txtZw.Text = dr["workzw"].ToString();
                this.txtBz.Text = dr["workbz"].ToString();
                this.drpType.Items.Add(dr["worksubm"].ToString());
                this.FCKeditor1.Value = dr["content"].ToString();
                Session["picture"] = dr["picture"].ToString();
            }
        }
    }
    //修改
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Session["manId"].ToString());
        string name = this.txtName.Text;
        string zw = this.txtZw.Text;
        string bz = this.txtBz.Text;
        string picture = this.FileUpload1.PostedFile.FileName;

        string content = this.FCKeditor1.Value.ToString();
        string fileName = "images/" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
        if (!picture.Equals(""))
        {
            if (Path.GetExtension(picture).Equals(".gif") || Path.GetExtension(picture).Equals(".jpg") || Path.GetExtension(picture).Equals(".jpeg") || Path.GetExtension(picture).Equals(".png"))
            {
                fileName += Path.GetExtension(picture);
                string sql = "update workMan set name='" + name + "',workzw='" + zw + "',workbz='" + bz + "',picture='" + fileName + "',content='" + content + "' where id=" + id;

                if (dao.getComm(sql) != 0)
                {
                    Server.Transfer("ygMessage.aspx");
                }
                else
                {
                    RegisterStartupScript("check", "<script language='javascript'>alert('修改失败');</script>");
                }
            }
            else
            {
                RegisterStartupScript("check", "<script language='javascript'>alert('将图片格式改为*.jpg或*.gif或*.jpeg或*.png');</script>");
            }
        }
        else
        {
            string sql1 = "update workMan set name='" + name + "',workzw='" + zw + "',workbz='" + bz + "',picture='" + Session["picture"].ToString() + "',content='" + content + "' where id=" + id;
            if (dao.getComm(sql1) != 0)
            {
                Server.Transfer("ygMessage.aspx");
            }
            else
            {
                RegisterStartupScript("check", "<script language='javascript'>alert('更新失败');</script>");
            }

        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Server.Transfer("ygMessage.aspx");
    }
}
